'use strict';

angular.module('app')
	.controller('postReCommentController', [ '$rootScope', '$scope', '$http', '$state',
	                                function($rootScope, $scope, $http, $state) {
		$scope.title = '相关推荐设置';
        $scope.param = { };
        $scope.loading = false;

		$scope.search = function () {
	        $scope.loading = true;
			$.ajax({
				url : $scope.app.project_name + '/postRecomment/recomment/list',
				data: $scope.param
			}).then(function(result) {
		        $scope.loading = false;
				if (result.httpCode == 200) {
					$scope.pageInfo = result.data;
					console.log("======")
					console.log(result.data);
				} else {
					$scope.msg = result.msg;
				}
				$scope.$apply();
			});
		}
                                        $scope.searchRe = function () {
                                            $scope.loading = true;
                                            $scope.param.pageNum=1;
                                            $.ajax({
                                                url : $scope.app.project_name + '/postRecomment/recomment/list',
                                                data: $scope.param
                                            }).then(function(result) {
                                                $scope.loading = false;
                                                if (result.httpCode == 200) {
                                                    $scope.pageInfo = result.data;
                                                    console.log(result.data);
                                                } else {
                                                    $scope.msg = result.msg;
                                                }
                                                $scope.$apply();
                                            });
                                        }

                                        $scope.getForumChannelList = function (){
                                            $.ajax({
                                                url : $scope.app.project_name + '/myChannel/getForumChannelList'
                                            }).then(function(result) {
                                                $scope.loading = false;
                                                if (result.httpCode == 200) {
                                                    $scope.channelList = result.data;
                                                } else {
                                                    $scope.msg = result.msg;
                                                }
                                                $scope.$apply();
                                            });
                                        }
        $scope.search();
                                        $scope.getForumChannelList();
        $scope.clearSearch = function() {
            $scope.param={};
            $scope.search();
        }

                                        $scope.approveupdate = function(channelNo,channelName,recommentPostId){
                                            $scope.firstApply1 = true;
                                            $scope.channelNo=channelNo;
                                            $scope.channelName=channelName;
                                            $scope.recommentPostId=recommentPostId;
                                            $("#recommentPostId").attr("readonly",false);
                                            $(".subbtn").show();

                                        }
                                        $scope.approvelook = function(channelNo,channelName,recommentPostId){
                                            $scope.firstApply1 = true;
                                            $scope.channelNo=channelNo;
                                            $scope.channelName=channelName;
                                            $scope.recommentPostId=recommentPostId;
                                            $("#recommentPostId").attr("readonly",true);
                                            $(".subbtn").hide();

                                        }
		// 翻页
        $scope.pagination = function (page) {
            $scope.param.pageNum=page;
            $scope.search();
        };
                                        $scope.updateRecomment=function(){
                                            $scope.loading = true;
                                            var param={"channelNo":$scope.channelNo,"recommentPostId":$scope.recommentPostId};
                                            $.ajax({
                                                url : $scope.app.project_name + '/postRecomment/recomment/update',
                                                data: param
                                            }).then(function(result) {
                                                $scope.loading = false;
                                                if (result.httpCode == 200) {
                                                    $scope.firstApply1 = false;
                                                    $scope.search();
                                                } else {
                                                    alert("请求失败");
                                                }
                                                $scope.$apply();
                                            });

                                        }
                                        $scope.deleteRecomment=function(channelNo){
                                            $scope.loading = true;
                                            $.ajax({
                                                url : $scope.app.project_name + '/postRecomment/recomment/delete',
                                                data: {"channelNo":channelNo}
                                            }).then(function(result) {
                                                $scope.loading = false;
                                                if (result.httpCode == 200) {
                                                    $scope.search();
                                                } else {
                                                    alert("请求失败");
                                                }
                                                $scope.$apply();
                                            });

                                        }
} ]);